package com.monkey.algorithm.chapter2

/**
 * 作者：Monkey
 * 日期：2018/2/10
 */
object InsertionSort : BaseExample() {
    override fun <T> sort(arr: Array<Comparable<T>>) {
        val N = arr.size
        for (i in 1 until N) {
            (i downTo 1)
                    .asSequence()
                    .filter { less(arr[it], arr[it - 1]) }
                    .forEach { swap(arr, it, it -1) }
        }
    }
}